package com.dream.cgomallcore.util;

import java.text.DecimalFormat;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Random;
import java.util.stream.DoubleStream;

public class GenerateRedPackageQueue {
    private static Random random =new Random();
    private static final Queue<Double> queue=new LinkedList();
    private static final DecimalFormat df = new DecimalFormat("#.00");

    public static synchronized Queue<Double> createQueue(int count,double money){
        int min=count-1;
        double bound=0;
        for (int i = 0; i < count; i++) {
            double eachMoney;
            bound=(money-min)+1;
            DoubleStream each= random.doubles(1,0,bound);
            eachMoney=Double.valueOf(df.format(each.toArray()[0]));
            queue.add(eachMoney);
            money-=eachMoney;
            min--;
            if(money<1){
                queue.add(money);
                break;
            }
        }

        return queue;
    }
}
